package com.plian.system.controller.fr.indicatorsstvalue;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.annotation.LogOperation;
import com.plian.system.config.exception.MyRuntimeException;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.service.fr.indicatorsstdvalue.IndicatorsStdvalueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List;

/**
 * 说明：指标标准值表
 * 创建时间:2020-06-08 14:34:54
 */
@RestController
@RequestMapping(value = "api/indicators_stdvalue")
public class IndicatorsStdvalueController extends BaseController {

    @Autowired
    private IndicatorsStdvalueService indicatorsstdvalueService;


    /**
     * 保存
     *
     * @param
     * @throws Exception
     */
    @PostMapping(value = "/save")
    @LogOperation("指标标准值-保存")
    public ObjResult save(@RequestBody PageData pd) throws Exception {
        return indicatorsstdvalueService.save(pd);
    }

    /**
     * 修改
     *
     * @param
     * @throws Exception
     */
    @PostMapping(value = "/edit")
    @LogOperation("指标标准值-编辑")
    public ObjResult edit(@RequestBody PageData pd) throws Exception {
        return indicatorsstdvalueService.edit(pd);
    }

    /**
     * 根据id查询
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/findbyid")
    public ObjResult findbyid(@RequestBody PageData pd) throws Exception {
        return indicatorsstdvalueService.findbyid(pd);
    }

    @PostMapping(value = "/findidAll")
    public ObjResult findidAll(@RequestBody PageData pd) throws Exception {
        return indicatorsstdvalueService.findidAll(pd);
    }

    /**
     * 根据集合删除数据
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/del_ids")
    @LogOperation("指标标准值-删除")
    public ObjResult delids(@RequestBody PageData pd) throws Exception {
        return indicatorsstdvalueService.del_ids((List<String>) pd.get("ids"));
    }

    /**
     * 导入
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/importExcel")
    @LogOperation("指标标准值-导入")
    public ObjResult importExcel(MultipartHttpServletRequest request) {
        return indicatorsstdvalueService.importExcel(request.getFile("file"));
    }

    /**
     * 下载模板
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/exportTemplateExcel")
    @LogOperation("指标标准值-导入")
//	@PassToken
    public void exportTemplateExcel(HttpServletResponse response, OutputStream os) {
        indicatorsstdvalueService.exportTemplateExcel(response, os);
    }

    /**
     * 查询列表
     *
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/list")
    public ListResult listpage(@RequestBody PageData pd) throws Exception {
        return indicatorsstdvalueService.listPage(pd);
    }

    @RequestMapping(value = "/calculation")
    @LogOperation("指标标准值-指标计算")
//	@PassToken
    public ObjResult calculation() {
        try {
            ObjResult objResult = new ObjResult(CommonCode.SUCCESS);
            indicatorsstdvalueService.calculation();
            return objResult;
        } catch (Exception e) {
            throw new MyRuntimeException();
        }
    }
}
